local shuangjue = fk.CreateSkill{
  name = "hanqing__shuangjue",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__shuangjue"] = "霜髉",
  [":hanqing__shuangjue"] = "锁定技，每轮结束时，若固定于中央区的牌数大于场上角色数，你令所有角色非锁定技失效至此技能结算结算并选择一名角色，"..
  "从该角色开始，所有角色依次使用中央区固定的一张牌直到无法使用，若你未因此使用牌，你获得中央区剩余的牌。",

  ["#hanqing__shuangjue-choose"] = "霜髉：请选择一名角色，从该角色开始使用中央区固定的牌！",
  ["#hanqing__shuangjue-use"] = "霜髉：请使用一张被固定的牌",
}

shuangjue:addEffect(fk.RoundEnd, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(shuangjue.name) and player.room:getBanner("@$CenterArea") and
      #table.filter(player.room:getBanner("@$CenterArea"), function (id)
        return Fk:getCardById(id):getMark("@@hanqing__fengrang") > 0
      end) > #player.room.alive_players
  end,
  on_cost = function (self, event, target, player, data)
    event:setCostData(self, {tos = player.room:getAlivePlayers()})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      skill_name = shuangjue.name,
      prompt = "#hanqing__shuangjue-choose",
      cancelable = false,
    })[1]
    local yes = true
    for _, p in ipairs(room.players) do
      room:addPlayerMark(p, MarkEnum.UncompulsoryInvalidity, 1)
    end
    while true do
      local cards = table.filter(room:getBanner("@$CenterArea") or {}, function (id)
        return Fk:getCardById(id):getMark("@@hanqing__fengrang") > 0
      end)
      if #cards == 0 then break end
      if room:askToUseRealCard(to, {
        pattern = cards,
        skill_name = shuangjue.name,
        prompt = "#hanqing__shuangjue-use",
        extra_data = {
          bypass_times = true,
          extraUse = true,
          expand_pile = cards,
        },
        cancelable = false,
      }) then
        if to == player then
          yes = false
        end
      else
        break
      end
      to = to:getNextAlive()
    end
    if yes and not player.dead and #(room:getBanner("@$CenterArea") or {}) > 0 then
      room:moveCardTo(room:getBanner("@$CenterArea"), Card.PlayerHand, player, fk.ReasonJustMove, shuangjue.name, nil, true, player)
    end
    for _, p in ipairs(room.players) do
      room:removePlayerMark(p, MarkEnum.UncompulsoryInvalidity, 1)
    end
  end,
})

shuangjue:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return shuangjue
